{
 "metadata": {
  "name": "",
  "signature": "sha256:68575190f5e51eb5ac1730684940159b2f94b5a5a9e6f5c0dd587dcdb16b7417"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import os\n",
      "os.chdir(os.path.dirname(os.getcwd()))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 1
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from meka.meka import Meka\n",
      "java_path = os.path.join(os.environ['JAVA_HOME'], 'bin', 'java')\n",
      "meka_path = os.path.join(os.environ['MEKA_HOME'], 'lib', '')\n",
      "meka_train = os.path.abspath(\"meka/data/scene-train.arff\")\n",
      "meka_test = os.path.abspath(\"meka/data/scene-test.arff\")\n",
      "meka_classifier = \"weka.classifiers.bayes.NaiveBayes\"\n",
      "meka = Meka(\"meka.classifiers.multilabel.MULAN -S MLkNN\", meka_classifier, java_path, meka_path)\n",
      "meka_predictions, meka_statistics = meka.run(meka_train, meka_test)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "C:\\Development\\Java\\jdk1.7.0_67\\bin\\java -cp \"D:\\Classification\\meka\\lib\\*\" meka.classifiers.multilabel.MULAN -S MLkNN -threshold 0 -t D:\\Classification\\scikit-multilearn\\meka\\data\\scene-train.arff -T D:\\Classification\\scikit-multilearn\\meka\\data\\scene-test.arff -verbosity 6 -W weka.classifiers.bayes.NaiveBayes\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from skmultilearn.dataset import Dataset\n",
      "from skmultilearn.lazy.mlknn import KNearestNeighbours\n",
      "skml_train = Dataset.load_dataset_dump(\"skmultilearn/data/scene-train.dump.bz2\")\n",
      "skml_test = Dataset.load_dataset_dump(\"skmultilearn/data/scene-test.dump.bz2\")\n",
      "skml = KNearestNeighbours()\n",
      "skml.fit(skml_train['X'], skml_train['y'])\n",
      "skml_predictions = skml.predict(skml_test['X'])"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 3
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import numpy as np\n",
      "import sklearn.metrics\n",
      "print(\"### Predictions equality ###\")\n",
      "print(np.array_equal(np.array(meka_predictions), skml_predictions))\n",
      "print(\"### Hamming loss ###\")\n",
      "print(\"SKML: %f\" % sklearn.metrics.hamming_loss(skml_test['y'], skml_predictions))\n",
      "print(\"MEKA: %f (%s)\" % (sklearn.metrics.hamming_loss(skml_test['y'], np.array(meka_predictions)), meka_statistics['Hammingloss']))\n",
      "print(\"### Accuracy score ###\")\n",
      "print(\"SKML: %f\" % sklearn.metrics.accuracy_score(skml_test['y'], skml_predictions))\n",
      "print(\"MEKA: %f (%s)\" % (sklearn.metrics.accuracy_score(skml_test['y'], np.array(meka_predictions)), meka_statistics['Accuracy']))\n",
      "print(\"### F1 score ###\")\n",
      "print(\"SKML: %f\" % sklearn.metrics.f1_score(skml_test['y'], skml_predictions))\n",
      "print(\"MEKA: %f (%s)\" % (sklearn.metrics.f1_score(skml_test['y'], np.array(meka_predictions)), meka_statistics['F1microavg']))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "### Predictions equality ###\n",
        "False\n",
        "### Hamming loss ###\n",
        "SKML: 0.090022\n",
        "MEKA: 0.156773 (0.819)\n",
        "### Accuracy score ###\n",
        "SKML: 0.605351\n",
        "MEKA: 0.130435 (0.181)\n",
        "### F1 score ###\n",
        "SKML: 0.719179\n",
        "MEKA: 0.207426 (0.307)\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}